﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

using YT.Modules;
using YT.DB;
using YT.Commons; 

namespace YT.XH.NOSE
{
    public partial class frmNSMsgDetail : Form
    {
        private DBAccess mdbcon = new DBAccess(false, false);
        private string mstrRecID = string.Empty;
        public frmNSMsgDetail()
        {
            InitializeComponent();
        }

        public frmNSMsgDetail(string strRecID)
        {
            InitializeComponent();
            mstrRecID = strRecID;
        }

        private void FillDetail()
        {
            string strSQL = string.Empty;

            strSQL = "select * from mSmsMessage where recID='" + mstrRecID + "'";
            DataRow drRow = mdbcon.GetDataFirstRow(strSQL);
            if (drRow != null)
            {
                txtSmsDesc.Text = CvtFunc.ToString(drRow["SmsDesc"]);
                txtSmsMessage.Text = CvtFunc.ToString(drRow["SmsMessage"]);
                txtType.Text = CvtFunc.ToString(drRow["Type"]);
            }
            else
            {
                txtSmsDesc.Text ="";
                txtSmsMessage.Text = "";
                txtType.Text = "";
            }
        }

        private void frmNSMsgDetail_Load(object sender, EventArgs e)
        {
            FillDetail();
            txtType.Focus(); 
        }

        private void btnSave_Click(object sender, EventArgs e)
        {
            string strSQL = string.Empty;

            if (mstrRecID == "")
            {
                strSQL = "INSERT INTO mSmsMessage ( Type,SmsMessage,SmsDesc )" +
                        "VALUES ('{0}','{1}','{2}')";
            }
            else
            {
                strSQL = "update mSmsMessage set Type='{0}',SmsMessage='{1}',SmsDesc='{2}' where recid='" + mstrRecID + "' ";                    
            }
            strSQL = string.Format(strSQL, txtType.Text, txtSmsMessage.Text, txtSmsDesc.Text);
            mdbcon.ExecuteSql(strSQL);
            this.Close(); 
        }

        private void btnExit_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        private void btnDel_Click(object sender, EventArgs e)
        {
            string strSQL= "Delete from mSmsMessage where recid='"+ mstrRecID +"'";
            mdbcon.ExecuteSql(strSQL);
            this.Close(); 
        }


    }
}
